
//
//  NewsPageNavView.m
//  ShowYork
//
//  Created by hxh on 2020/8/28.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "NewsPageNavView.h"

@interface NewsPageNavView ()
@property (nonatomic,strong)UIView *searchView;
@property (nonatomic,strong)UILabel *searchLb;
@property (nonatomic,strong)UIButton *centerBtn;
@property (nonatomic,strong)UIImageView *searchImgView;
@property (nonatomic,strong)UIButton *searchBtn;
@property (nonatomic,strong)UIImageView *centerImgView;
@property (nonatomic,strong)UILabel *centerLb;
@property (nonatomic,strong)UIImageView *backImgView;
@property (nonatomic,strong)UIButton *backBtn;
@end

@implementation NewsPageNavView

- (instancetype)initWithDelegate:(id<NewsPageNavViewDelegate>)delegate{
    if (self = [super init]) {
        self.delegate = delegate;
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.frame = CGRectMake(0, 0, kScreenW, 44 + GK_STATUSBAR_HEIGHT);
    
  
    self.searchView = [[UIView alloc]init];
    self.searchView.layer.cornerRadius = 18;
    self.searchView.layer.borderWidth = 1;
    self.searchView.layer.borderColor = C(230, 1).CGColor;
    self.searchView.layer.masksToBounds = YES;
    
    [self addSubview:self.searchView];

    self.centerBtn = [[UIButton alloc]init];
    [self.centerBtn addTarget:self action:@selector(collectListMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.centerBtn];
    
    
    self.centerLb = [[UILabel alloc]init];
    self.centerLb.text = @"收藏夹";
    self.centerLb.textColor = C102;
    self.centerLb.font = font(10);
    [self addSubview:self.centerLb];
    
    self.centerImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"news_collect_tag"]];
    self.centerImgView.highlightedImage = [UIImage imageNamed:@"news_collect_tag"];
    [self addSubview:self.centerImgView];
    
    
    self.searchLb = [[UILabel alloc]init];
    self.searchLb.text = @"搜索你感兴趣的…";
    self.searchLb.textColor = C(210, 1);
    self.searchLb.font = font(14);
    [self addSubview:self.searchLb];
    
    
    self.searchImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"news_search_tag"]];
    [self addSubview:self.searchImgView];
    
    
    self.searchBtn = [[UIButton alloc]init];
    [self.searchBtn addTarget:self action:@selector(searchMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.searchBtn];
    
    self.backImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_back_tag"]];
    self.backImgView.highlightedImage = [UIImage imageNamed:@"common_back_tag"];
    [self addSubview:self.backImgView];
    
    self.backBtn = [[UIButton alloc]init];
    [self.backBtn addTarget:self action:@selector(backMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.backBtn];
    
    [self.backImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.bottom.mas_equalTo(self).offset(-12);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];

    [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(32);
        make.centerY.mas_equalTo(self.backImgView);
        make.right.equalTo(self.centerBtn.mas_left);
        make.left.equalTo(self.backImgView.mas_right).offset(12);
    }];
       
    [self.searchImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.searchView);
        make.left.equalTo(self.searchView).offset(8);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.searchLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.searchView);
        make.left.equalTo(self.searchImgView.mas_right).offset(3);
        make.right.equalTo(self.searchView).offset(-18);
    }];
    
    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.searchView);
    }];

    [self.centerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.right.equalTo(self);
        make.width.mas_equalTo(44);
    }];
    [self.centerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchView);
        make.centerX.equalTo(self.centerBtn);
    }];
    [self.centerLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.centerImgView.mas_bottom);
        make.centerX.equalTo(self.centerImgView);
    }];
}

- (void)backMethod{
    if(self.delegate && [self.delegate respondsToSelector:@selector(popViewController)]){
        [self.delegate popViewController];
    }
}


- (void)searchMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showSearch)]) {
        [self.delegate showSearch];
    }
}
- (void)collectListMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showCollectList)]) {
        [self.delegate showCollectList];
    }
}



@end
